package com.xhj.xmly.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.xhj.xmly.bean.ListType;
import com.xhj.xmly.R;

import java.util.List;


/**
 * Created by fangjh on 2016/12/5.
 */

public class DiscoverListAdapter extends RecyclerView.Adapter<DiscoverListAdapter.ViewHolder>{

    private Context context;
    private List<ListType.DatasBean.ListBeanX> dataList;

    public DiscoverListAdapter(Context context, List<ListType.DatasBean.ListBeanX> dataList) {
        this.context = context;
        this.dataList = dataList;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(context).inflate(R.layout.fra_discover_list_item,parent,false);
        ViewHolder holder=new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.tv1.setText(dataList.get(position).getTitle());
        holder.tv2.setText(dataList.get(position).getFirstKResults().get(0).getTitle());
        holder.tv3.setText(dataList.get(position).getFirstKResults().get(1).getTitle());
        String url=dataList.get(position).getCoverPath();
        Picasso.with(context).load(url).into(holder.iv);
    }

    @Override
    public int getItemCount() {
        return dataList.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder{
        private TextView tv1,tv2,tv3;
        private ImageView iv;
        public ViewHolder(View itemView) {
            super(itemView);
            tv1= (TextView) itemView.findViewById(R.id.fra_discover_list_title);
            tv2= (TextView) itemView.findViewById(R.id.fra_discover_list_SonFristTitle);
            tv3= (TextView) itemView.findViewById(R.id.fra_discover_list_SonSecondTitle);
            iv= (ImageView) itemView.findViewById(R.id.fra_discover_list_iv);
        }
    }
}
